<? include("/inc/header.html") {} ?>
	<div class="page-content" style="margin-top: -15px;">
		<div class="row mbl" style="overflow: auto;height: 100%;">
			<div class="col-lg-6">
				<div class="portlet box">
                    <div class="portlet-header">
                        <div class="caption">试卷</div>
                    </div>
                    <div class="portlet-body" style="height: 90%;overflow: auto;">
                        <div class="table-responsive">
						<div id="example1_wrapper"
							class="dataTables_wrapper form-inline no-footer">
							<table style="font-size: 15px;" class="table table-striped table-bordered table-hover dataTable no-footer">
								<thead>
									<tr>
										<th >题号</th>
										<th >题目</th>
										<th >类型</th>
										<th style="width: 60px;">操作</th>
									</tr>
								</thead>
								<tbody id="shijuan">
									<!-- <tr>
										<td >Gecko</td>
										<td>Firefox 1.0</td>
										<td>Win 98+ / OSX.2+</td>
										<td><a href="javascript:;" class="delete">Delete</a></td>
									</tr> -->
								</tbody>
							</table>
						</div>
					</div>
                    </div>
                </div>
			</div>
			<div class="col-lg-6">
				<div class="portlet box">
                    <div class="portlet-header">
                        <div class="caption">所有题目</div>
                    </div>
                    <div class="portlet-body" style="height: 90%;overflow: auto;">
                        <div class="table-responsive">
						<div id="example1_wrapper"
							class="dataTables_wrapper form-inline no-footer">
							<div class="row">
								<div class="col-md-12">
									<div id="example1_filter" class="dataTables_filter">
										<label>
											<div class="input-group input-group-sm mbs">
												<span class="input-group-btn" style="font-size: 12px;">
													题目名称：
												</span>
												<input type="text" id="name2" class="form-control input-sm">
											</div>
										</label>
										<label>
											<div class="input-group input-group-sm mbs">
												<span class="input-group-btn" style="font-size: 12px;">
													题目类型：
												</span>
												<select class="form-control" id="type2" style="width: 200px;">
													<option value="">全部</option>
													<option value="0">单选题</option>
													<option value="1">判断题</option>
													<option value="2">问答题</option>
												</select>	
											</div>
										</label>
										<label>
											<div class="input-group input-group-sm mbs">
												<span class="input-group-btn" style="font-size: 12px;">
													所属题库：
												</span>
												<select class="form-control" id="questionDatabaseId" style="width: 200px;">
													
												</select>	
											</div>
										</label>
										<label>
											<div class="input-group input-group-sm mbs">
												<span class="input-group-btn">
													<button type="button" data-toggle="dropdown" class="btn btn-blue dropdown-toggle" onclick="get2()">查询</button>
												</span>
											</div>
										</label>
									</div>
								</div>
							</div>
							<table style="font-size: 15px;" class="table table-striped table-bordered table-hover dataTable no-footer">
								<thead>
									<tr>
										<th >题号</th>
										<th >题目</th>
										<th >类型</th>
										<th style="width: 60px;">操作</th>
									</tr>
								</thead>
								<tbody id="timu">
									<!-- <tr>
										<td>Gecko</td>
										<td>Firefox 1.0</td>
										<td>Win 98+ / OSX.2+</td>
										<td><a href="javascript:;" class="delete">Delete</a></td>
									</tr> -->
								</tbody>
							</table>
							<div id="page2" style="text-align: center; margin-top: 20px;"></div>
						</div>
					</div>
                    </div>
                </div>
			</div>
		</div>
		<input type="hidden" id="paperId" value="${id}">
		<input type="hidden" id="type" value="${type}">
		<input type="hidden" id="resourceId" value="${resourceId}">
	</div>


<script>
	var curr;
	$(function(){
		demo1();
		demo2(1);
		init();
	});
	
function init(){
		$.ajax({
				type : "post",
				url : "./questionDatabaseAll.do",
				dataType : "json",
				success : function(data) {
					var html='<option value="">全部</option>';
					for(var i in data){
						html+='<option value="'+data[i].id+'">'+data[i].name+'</option>';
					}
					$("#questionDatabaseId").html(html);
				},
				error : function(data) {
					alert("请求失败");
				}
			});
	
	}
	
	function get2(){
		demo2(1);
	}
	function demo1() {
		var url="";
		if($("#type").val()=='0'){//课程
			url="./getCourseQuestionList.do";
		}else if($("#type").val()=='1'){//微课
			url="./getOnlineQuestionList.do";
		}else if($("#type").val()=='2'){//直播
			url="./getLiveQuestionList.do";
		}
		
		$.getJSON(url,
			{
        		id:$("#paperId").val()
			},
			function(res) {
				//此处仅仅是为了演示变化的内容
				var str = "";
				for ( var i = 0; i < res.length; i++) {
					str += "<tr><td>"
							+ (res.length-i)
							+ "</td><td> <label>"
							+ res[i].name
							+ "</label></td><td><label >";
							if(res[i].type=='0'){
								str+='单选题';
							}else if(res[i].type=='1'){
								str+='判断题';
							}else if(res[i].type=='2'){
								str+='问答题';
							}
							str+= "</label></td><td>"
							+ "<button type=\"button\" class=\"btn btn-red btn-xs\"  onclick=\"delQuestion('"
							+ res[i].id
							+ "')\">"
							+ "删除"
							+ "</a>&nbsp;"
							+ "</td></tr>";
				}
				$("#shijuan").html(str);
			});
	};
	function demo2(cur) {
		$.getJSON("./questionList.do",
			{
				page : cur || 1,
				name:$("#name2").val(),
        		type:$("#type2").val(),
        		questionDatabaseId:$("#questionDatabaseId").val(),
        		status:"2",
        		pageSize:10
			},
			function(res) {
				//此处仅仅是为了演示变化的内容
				var str = "";
				for ( var i = 0; i < res.listsize; i++) {
					str += "<tr><td>"
							+ (i + 1)
							+ "</td><td> <label>"
							+ res.result[i].name
							+ "</label></td><td><label >";
							if(res.result[i].type=='0'){
								str+='单选题';
							}else if(res.result[i].type=='1'){
								str+='判断题';
							}else if(res.result[i].type=='2'){
								str+='问答题';
							}
							str+= "</label></td><td>"
							+ "<button type=\"button\" class=\"btn btn-blue btn-xs\" onclick=\"selectQuestion('"
							+ res.result[i].id
							+ "')\">"
							+ "选择"
							+ "</button>&nbsp;"
							+ "</td></tr>";
				}
				$("#timu").html(str);
				laypage({
					cont : document.getElementById('page2'), //容器。值支持id名、原生dom对象，jquery对象,
					pages : res.pageSize, //总页数
					skip : true, //是否开启跳页
					skin : 'molv', //加载内置皮肤，也可以直接赋值16进制颜色值，如:#c00
					curr: cur || 1,
					last: res.pageSize,
					groups : 6,//连续显示分页数
					jump : function(obj, first) { //触发分页后的回调
						if (!first) { //点击跳页触发函数自身，并传递当前页：obj.curr
							demo2(obj.curr);
			                 curr=obj.curr;
						}
					}
				});
			});
	};
	
	function selectQuestion(id){
		if($("#type").val()=='0'){//课程
			selectCourseQuestion(id);
		}else if($("#type").val()=='1'){//微课
			selectOnlineQuestion(id);
		}else if($("#type").val()=='2'){//直播
			selectLiveQuestion(id);
		}
	}
	function delQuestion(id){
		if($("#type").val()=='0'){//课程
			delCourseQuestion(id);
		}else if($("#type").val()=='1'){//微课
			delOnlineQuestion(id);
		}else if($("#type").val()=='2'){//卷子
			delLiveQuestion(id);
		}
	}
	function selectCourseQuestion(id){
		$.ajax({
				type : "post",
				url : "./courseQuestionAddUpdate.do",
				data : {
					"questionId" : id,
					"courseId":$("#resourceId").val(),
					"paperId":$("#paperId").val(),
				},
				dataType : "json",
				success : function(data) {
					if(data[0].result=='success'){
						demo1();
					}
					layer.msg(data[0].msg);
				},
				error : function(data) {
					alert("请求失败");
				}
			});
	}
	function selectOnlineQuestion(id){
		$.ajax({
				type : "post",
				url : "./onlineQuestionAddUpdate.do",
				data : {
					"questionId" : id,
					"onlineId":$("#resourceId").val(),
					"paperId":$("#paperId").val(),
				},
				dataType : "json",
				success : function(data) {
					if(data[0].result=='success'){
						demo1();
					}
					layer.msg(data[0].msg);
				},
				error : function(data) {
					alert("请求失败");
				}
			});
	}
	function selectLiveQuestion(id){
		$.ajax({
				type : "post",
				url : "./liveQuestionAddUpdate.do",
				data : {
					"questionId" : id,
					"liveId":$("#resourceId").val(),
					"paperId":$("#paperId").val(),
				},
				dataType : "json",
				success : function(data) {
					if(data[0].result=='success'){
						demo1();
					}
					layer.msg(data[0].msg);
				},
				error : function(data) {
					alert("请求失败");
				}
			});
	}
	function delCourseQuestion(id){
		$.ajax({
				type : "post",
				url : "./courseQuestionDel.do",
				data : {
					"id" : id,
				},
				dataType : "json",
				success : function(data) {
					if(data[0].result=='success'){
						demo1();
					}
					layer.msg(data[0].msg);
				},
				error : function(data) {
					alert("请求失败");
				}
			});
	}
	function delOnlineQuestion(id){
		$.ajax({
				type : "post",
				url : "./onlineQuestionDel.do",
				data : {
					"id" : id,
				},
				dataType : "json",
				success : function(data) {
					if(data[0].result=='success'){
						demo1();
					}
					layer.msg(data[0].msg);
				},
				error : function(data) {
					alert("请求失败");
				}
			});
	}
	function delLiveQuestion(id){
		$.ajax({
				type : "post",
				url : "./liveQuestionDel.do",
				data : {
					"id" : id,
				},
				dataType : "json",
				success : function(data) {
					if(data[0].result=='success'){
						demo1();
					}
					layer.msg(data[0].msg);
				},
				error : function(data) {
					alert("请求失败");
				}
			});
	}
</script>